import json
from os import makedirs
from os.path import exists

import requests
from bs4 import BeautifulSoup
from gevent import os

dirName = 'json'
filename = 'FreeDynamicWallpaper.json'

if __name__ == '__main__':
    txt = dirName + '/' + filename
    exist_file = exists(txt)
    if not exists(dirName):
        makedirs(dirName)
    empty = []

    for i in range(0, 63):
        name = "feature_" + str(i)
        video_url = "https://afra55.github.io/FreeDynamicWallpaper.github/video/" + name + ".mp4"
        preview_image_url = "https://afra55.github.io/FreeDynamicWallpaper.github/img/" + name + ".webp"
        theme = {
            'id': i,
            'name': name,
            'preview_image_url': preview_image_url,
            'video_url': video_url,
            'has_music': True
        }
        empty.append(theme)

    next_page = ''
    with open(txt, 'w', encoding='utf-8') as f:
        data_dict = {
            'themes': empty,
            'next_page': next_page
        }
        json_data = json.dumps(data_dict, indent=4)
        f.write(json_data)
        print(json_data)
        f.close()
